package com.demo14;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo {
    public static void main(String[] args) {
        //多态的方式来定义数据
        Map<String, String> hashMap = new HashMap<>();

        hashMap.put("金庸","天龙八部");
        hashMap.put("温瑞安","四大名捕");
        hashMap.put("古龙","小李飞刀");
        hashMap.put("梁羽生","萍踪侠影");

        System.out.println(hashMap.get("古龙"));
        System.out.println(hashMap.containsKey("金庸1"));

        Set<String> strings = hashMap.keySet();

        for (String key: strings){
            System.out.println(key+","+hashMap.get(key));
        }

        System.out.println("-----");
        Set<Map.Entry<String, String>> entrySet = hashMap.entrySet();

        for (Map.Entry<String,String> my: entrySet){
            System.out.println(my.getKey()+":"+my.getValue());
        }
    }
}
